package com.tarena.lbs.user.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.user.pojo.param.AdminParam;
import com.tarena.lbs.user.pojo.query.AdminQuery;
import com.tarena.lbs.user.pojo.vo.AdminVO;
import com.tarena.lbs.user.service.AdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "后台用户管理")
@RestController
public class AdminController {

    @Autowired
    private AdminService adminService;

    @ApiOperation("用户详情")
    @GetMapping("/admin/basic/role/detail")
    public Result<AdminVO> detail(@RequestHeader("Authorization") String token) throws BusinessException {
        AdminVO adminVO = adminService.getAdminDetail(token);
        return new Result<>(adminVO);
    }



    @ApiOperation("账号列表")
    @GetMapping("/admin/basic/role/list")
    public Result<List<AdminVO>> list(AdminQuery query) {
        log.info("controller 层查询账号列表");
        List<AdminVO> result = adminService.selectList(query);
        return new Result<>("0", "列表查询成功", result);
    }

    @ApiOperation("账号保存")
    @PostMapping("/admin/basic/role/add")
    public Result<Void> save(@RequestBody AdminParam param) throws BusinessException {
        adminService.saveAdmin(param);
        return Result.success();
    }
}